package com.ulook.lookplanet.widget;

import android.content.Context;
import android.content.Intent;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.ulook.lookplanet.R;
import com.ulook.lookplanet.base.WidgetData;
import com.ulook.lookplanet.data.model.TTopic;
import com.ulook.lookplanet.ui.square.community.CommunityActivity;
import com.ulook.lookplanet.ui.square.topic.TopicActivity;

/**
 * 描述：
 *
 * @author L1998
 * @data 2021/4/21
 */
public class TopicItemView extends LinearLayout implements WidgetData<TTopic> {

    private Context context;
    private TTopic topic;
    private int currUserId;

    public TopicItemView(Context context) {
        super(context);
        initTopicItemView(context);
    }

    public TopicItemView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        initTopicItemView(context);
    }

    public TopicItemView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initTopicItemView(context);
    }

    private void initTopicItemView(Context context){
        this.context = context;
        LayoutInflater.from(context).inflate(R.layout.widget_topic_item_view, this, true);
    }


    @Override
    public void setWidgetData(TTopic value) {
        this.topic = value;
        TextView textView = findViewById(R.id.w_topic_item_text);
        textView.setText(topic.getName());
    }

    @Override
    public void setWidgetData(TTopic value, int currUserID) {
        setWidgetData(value);
        this.currUserId = currUserID;
        /*this.setClickable(true);
        this.setOnClickListener(view -> {
            // 跳转话题页面
            Intent intent = new Intent(context, TopicActivity.class);
            intent.putExtra("topic", topic);
            intent.putExtra("currUserId", currUserId);
            context.startActivity(intent);
        });*/
    }

    public String getTopicUid(){
        return topic.getUid();
    }
}
